KaTeX macro
※ProjectScript が無效なので訪問者には macro が反映されない
code:script.js
console.info("👒KaTeX macro");
const macros = {};
function deco_parse(o_parse) {
return function parse() {
const hasdeftag = macros.hasOwnProperty("\\df@tag");
this.settings.macros = this.gullet.macros.current = macros;
try {
const res = o_parse.call(this);
return res;
} finally {
if (hasdeftag) {
}
}
};
}
const o_consolelog = console.log;
console.log = function logpatch(...args) {
if (args.length == 5 && args2.type === "verb") { o_consolelog("👒KaTeX macro/patch");
const macro_info = args2; let o_handler = macro_info.handler;
macro_info.handler = function (t, i, s) {
const o_parse = Object.getPrototypeOf(t.parser).parse;
Object.getPrototypeOf(t.parser).parse = deco_parse(o_parse);
//Object.getPrototypeOf(t.parser.settings).isTrusted = _=>true;
console.log = o_consolelog;
macro_info.handler = o_handler;
};
} else {
o_consolelog(...args);
}
};
function getReactFiber(obj) {
if (obj === null) return undefined;
}
const patch_code = "$ \\show \\verb $ \\verb{} ";
function enablepatch() {
switch (scrapbox.Layout) {
case "page":
const line = getReactFiber(
document.querySelector("#editor > div > div.lines > div:nth-child(2)"),
).return.stateNode;
line.props.children = patch_code;
line.props.codeBlock = undefined;
line.props.tableBlock = undefined;
line.props.cli = undefined;
line.props.helpfeel = undefined;
line.updater.enqueueForceUpdate(line);
break;
case "list":
getReactFiber(document.querySelector("li > a > div.content"))
.child.sibling.type({ page: {} })
.type({ page: { descriptions: "" } }) .props.children10.type({ children: patch_code }); break;
case "stream":
console.log("stream");
getReactFiber(
document.querySelector(
"div.stream > div.lazy-render > div.time-range > div.page > div.lines > div:last-child",
),
)
.child.type({ children: "" })
.props.children.type({ children: patch_code });
break;
default:
break;
}
}
enablepatch();
const app =
document.querySelector("#app-container")._reactRootContainer._internalRoot
.current.child.stateNode;
const display_style = app._stores.find(
(obj) => obj.constructor.name == "DisplayStyle",
);
function forceUpdate() {
app.onStoreChange();
app.onStoreChange();
}
forceUpdate();